package seatiger.tomcat.naming.resources;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 代表一个资源
 * 资源的流
 * 资源的内容 byte[]
 */
public class Resource {
    protected byte[] binaryContent;
    protected InputStream inputStream;

    public Resource(){
    }
    public Resource(InputStream inputStream){
        setContent(inputStream);
    }

    public Resource(byte[] binaryContent){
        setContent(binaryContent);
    }

    public InputStream streamContent() throws IOException {
        if (binaryContent != null){
            return new ByteArrayInputStream(binaryContent);
        }
        return inputStream;
    }

    public byte[] getContent() {
        return binaryContent;
    }

    public void setContent(InputStream inputStream){
        this.inputStream = inputStream;
    }

    public void setContent(byte[] binaryContent){
        this.binaryContent = binaryContent;
    }
}
